#include "gtlState.h"

namespace GTL { namespace Engine {

	Event::EventHandler* StateHolder::GetEvent( const char* name, bool noParentEvents )
	{
		for (GTL::AutoMembers::AutoMember* i=Children; i; i = i->NextSibling)
		{
			if (i->GetType() == 'even')
			{
				Event* ev = (Event*)i;
				if (ev->EventName == name)
					return &ev->Handler;
			}
		}
		if (!noParentEvents && ParentMember && ParentMember->GetType() == 'stat')
			return ((StateHolder*)ParentMember)->GetEvent(name, false);
		return 0;
	}

	StateHolder* StateHolder::FindState( const char* state )
	{
		for (GTL::AutoMembers::AutoMember* i=Children; i; i = i->NextSibling)
		{
			if (i->GetType() == 'stat')
			{
				StateHolder* ev = (StateHolder*)i;
				if (ev->StateName == state)
					return ev;
			}
		}
		return 0;
	}
}}